<div class="wrapper">
  <?php $this->partial('Common/mainHeader');?>

  <?php $this->partial('Common/mainSiderbar');?>

  <div class="content-wrapper">
    <section class="content-header">
          <h1>新会员<small>注册</small></h1>
      <ol class="breadcrumb">
        <li><a href="/"><i class="fa fa-fw fa-home"></i> 首页</a></li>
        <li><a href="javascript:void(0);">会员网络</a></li>
        <li class="active">新会员注册</li>
      </ol>
    </section>

    <div class="pad margin no-print">
      <div class="callout callout-danger" style="margin-bottom: 0!important;">
        <h4><i class="fa fa-fw fa-warning"></i> :警告</h4>
        1. 会员编号必须是5-10位数字，登录密码、二级密码，如不填写，则密码是123456。 <br />
        2. 注册1名新会员需要消耗直推人1个激活码，请牢记新会员的会员编号。 <br />
        3. 标有<i class="fa fa-fw bg-black text-red">*</i>的符号必须填写。
      </div>
    </div>

    <section class="content">
      <div class="row">
        <div class="col-md-12">
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">新用户注册</h3>
            </div>

            <form class="form-horizontal" action="/user/register/create" method="post" id="registerForm">
              <div class="box-body">
                <div class="form-group">
                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>服务中心</label>
                  <div class="col-sm-4">
                    <input type="text" class="form-control" value="<?php echo $currentUser['real_name'] . $currentUser['user_code']; ?>" disabled>
                    <input type="hidden" name="user[service_user_id]" value="<?php echo $currentUser['user_id']; ?>"/>
                  </div>

                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>会员编号</label>
                  <div class="col-sm-4"><input type="number" name="user[user_code]" value="<?php echo rand(10000, 99999999) ?>" class="form-control"></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>真实姓名</label>
                  <div class="col-sm-4"><input type="text" name="user[real_name]" class="form-control" required></div>

                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>手机号码</label>
                  <div class="col-sm-4"><input type="text" name="user[phone]" class="form-control" required></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">登录密码</label>
                  <div class="col-sm-4"><input type="password" name="user[password]" class="form-control" placeholder="不填写，默认123456"></div>

                  <label class="col-sm-2 control-label">确认登录密码</label>
                  <div class="col-sm-4"><input type="password" name="user[confirm_password]" class="form-control" placeholder="不填写，默认123456"></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">二级密码</label>
                  <div class="col-sm-4"><input type="password" name="user[safe_password]" class="form-control" placeholder="不填写，默认123456"></div>

                  <label class="col-sm-2 control-label">确认二级密码</label>
                  <div class="col-sm-4"><input type="password" name="user[confirm_safe_password]" class="form-control" placeholder="不填写，默认123456"></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>推荐人编号</label>
                  <div class="col-sm-4"><input type="text" name="promotion_user_code" value="<?php echo $currentUser['user_code'];?>" class="form-control" required></div>

                  <label class="col-sm-2 control-label">确认推荐人姓名</label>
                  <div class="col-sm-4"><input type="text" id="showPromotionUserName" value="<?php echo $currentUser['real_name'];?>" class="form-control" disabled></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>接点人编号</label>
                  <div class="col-sm-4"><input type="text" name="node_user_code" class="form-control" value="<?php echo $currentUser['user_code']; ?>" required></div>

                  <label class="col-sm-2 control-label">确认接点人姓名</label>
                  <div class="col-sm-4"><input type="text" id="showNodeUserName" class="form-control" value="<?php echo $nodeSideMessage; ?>" disabled></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label"><i class="fa fa-fw text-red">*</i>选择市场</label>
                  <div class="col-sm-4" id="showUserNodeSideSelect">
                    <?php if($nodeSide) { ?>
                      <select name="user[node_side]" class="form-control" required>
                        <?php foreach($nodeSide as $k => $v) { ?>
                          <option value="<?php echo $k; ?>"><?php echo $v; ?></option>
                        <?php } ?>
                      </select>
                    <?php } ?>
                  </div>

                  <label class="col-sm-2 control-label">性别</label>
                  <div class="col-sm-4">
                    <label class="control-label"><input type="radio" name="user_info[sex]" value="1">男</label>
                    <label class="control-label"><input type="radio" name="user_info[sex]" value="0">女</label>
                    <label class="control-label"><input type="radio" name="user_info[sex]" value="2" checked="checked">隐藏</label>
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">地址</label>
                  <div class="col-sm-10 row" id="selectAddress">
                    <div class="col-sm-4"><select name="province_code" class="form-control"></select></div>
                    <div class="col-sm-4"><select name="city_code" class="form-control"></select></div>
                    <div class="col-sm-4"><select name="district_code" class="form-control"></select></div>
                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">详细地址</label>
                  <div class="col-sm-4"><input type="text" name="user_info[address_detail]" class="form-control"></div>

                  <label class="col-sm-2 control-label">身份证号</label>
                  <div class="col-sm-4"><input type="text" name="user_info[identity_card]" class="form-control"></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">银行名称</label>
                  <div class="col-sm-4"><input type="text" name="user_info[bank_name]" class="form-control"></div>

                  <label class="col-sm-2 control-label">银行账号</label>
                  <div class="col-sm-4"><input type="text" name="user_info[bank_account]" class="form-control"></div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label">开户人姓名</label>
                  <div class="col-sm-4"><input type="text" name="user_info[bank_account_name]" class="form-control"></div>

                  <label class="col-sm-2 control-label">开户支行</label>
                  <div class="col-sm-4"><input type="text" name="user_info[bank_deposit]" class="form-control"></div>
                </div>
              </div>

              <div class="box-footer"><button type="submit" class="btn btn-primary">确认注册</button></div>
            </form>
          </div>
        </div>
      </div>
    </section>
  </div>

  <?php $this->partial('Common/mainFooter');?>
</div>

<?php $this->partial('Common/mainScript');?>
<script type="text/javascript" charset="utf-8" src="/node_modules/jquery-validation/dist/jquery.validate.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/node_modules/jquery-validation/dist/localization/messages_zh.js"></script>
<script type="text/javascript" charset="utf-8" src="/node_modules/distpicker/dist/distpicker.min.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    var tokenInput = $('input[name="token"]');
    jQuery.validator.setDefaults({
      debug: true,
      onclick: false,
      onkeyup: false,
      errorElement: "span",
      errorPlacement: function(error, element) {
        error.addClass('help-block').insertAfter(element);
      },
      highlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').addClass('has-error').removeClass('has-success');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.form-group').removeClass('has-error').addClass('has-success');
      }
    });

    $('#registerForm').validate({
      submitHandler: function(form) {
        var $form = $(form);
        var findButton = $(form).find('button[type="submit"]');

        $.post($form.attr("action"), $form.serialize(), function(result) {
          findButton.attr("disabled", "disabled");
          alert(result.msg);
          if(result.code == 0) {
            //setInterval(function(){location.href=result.url;}, 1000);
            location.href=result.url;
            return true;
          }
          findButton.removeAttr("disabled");
        });
      }
    });

    $('input[name="promotion_user_code"]').change(function() {
      var _this = $(this);
      $.getJSON('/user/useUserCodeGetUserName?user_code=' + _this.prop('value')).done(function(result) {
        if(result.code !=0 ) {
          $('#showPromotionUserName').prop('value', result.message);
          return false;
        }
        $('#showPromotionUserName').prop('value', result.data.real_name);
      })
    });

    $('input[name="node_user_code"]').change(function() {
      var _this = $(this);
      $.getJSON('/user/useUserCodeGetUserNameAndNode?user_code=' + _this.prop('value')).done(function(result) {
        if(result.code !=0 ) {
          $('#showNodeUserName').prop('value', result.message);
          $('#showUserNodeSideSelect').html('');
          return false;
        }
        $('#showNodeUserName').prop('value', result.data.real_name);
        var nodeSideSelectHtml = '<select name="user[node_side]" class="form-control" required>';
        for(var k in result.data.node_side) {
          nodeSideSelectHtml += '<option value="' + k + '">' + result.data.node_side[k] + '</option>';
        }
        nodeSideSelectHtml += '</select>';
        $('#showUserNodeSideSelect').html(nodeSideSelectHtml);
      })
    });

    $("#selectAddress").distpicker({valueType: "code"});
  });
</script>
